// 企业数据访问层
package org.example.backend.repository;

import org.example.backend.entity.Company;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Optional;

@Repository
public interface CompanyRepository extends JpaRepository<Company, Long> {
    Optional<Company> findByUserId(Long userId);
    Optional<Company> findByUnifiedCode(String unifiedCode);
    Optional<Company> findByName(String name);

    @Query("SELECT c FROM Company c WHERE (:status IS NULL OR c.status = :status)")
    Page<Company> findByStatus(@Param("status") Integer status, Pageable pageable);

}
